//
//  ForumHeaderView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/29.
//

#import "ForumHeaderView.h"
#import "CommonUtil.h"

#import "RuleView.h"
#import "LotteryView.h"
#import "CommunityModel.h"
#import "CommunityTableViewCell.h"
#import "ForumHeaderView.h"

@interface ForumHeaderView()

@property (strong, nonatomic) UIImageView * bgImageView;
@property (strong, nonatomic) UILabel * tipLabel;
@property (strong, nonatomic) UILabel * titleLabel;
@property (strong, nonatomic) LotteryView * lotteryView;



@end

@implementation ForumHeaderView


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        

        [self addSubview:self.bgImageView];
        [self addSubview:self.lotteryView];
        [self addSubview:self.messageView];
        [self addSubview:self.tabView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.tipLabel];
        [self addSubview:self.backBtn];
        [self addSubview:self.searchBtn];
    }
    return self;
}

- (void)changeHeaderBG:(NSInteger)index{
    if (index == 0) {
        self.bgImageView.image = [UIImage imageNamed:@"香港bg"];
    }else if (index == 1){
        self.bgImageView.image = [UIImage imageNamed:@"新加坡bg"];
    }else if (index == 2){
        self.bgImageView.image = [UIImage imageNamed:@"澳门bg"];
    }else if (index == 3){
        self.bgImageView.image = [UIImage imageNamed:@"台湾bg"];
    }else if (index == 4){
        self.bgImageView.image = [UIImage imageNamed:@"时时彩bg"];
    }
}


-(UIButton *)backBtn{
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backBtn setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
        [_backBtn setTitle:@"返回" forState:UIControlStateNormal];
        [_backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _backBtn.frame = CGRectMake(AD(10), kStatusBarHeight + AD(7), AD(60), AD(30));
        _backBtn.imageEdgeInsets = UIEdgeInsetsMake(0, AD(-15), 0, 0);
    }
    return _backBtn;
}

-(UIButton *)searchBtn{
    if (!_searchBtn) {
        _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_searchBtn setImage:[UIImage imageNamed:@"icon_gaoshou_fenxiang"] forState:UIControlStateNormal];
        [_searchBtn setTitle:@"分享"  forState:UIControlStateNormal];
        [_searchBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _searchBtn.titleLabel.font = [UIFont systemFontOfSize:AD(14)];
        _searchBtn.frame = CGRectMake(SCREEN_WIDTH-AD(80), 0, AD(60), AD(30));
        _searchBtn.centerY = self.backBtn.centerY;
        _searchBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -AD(10));
    }
    return _searchBtn;
}




-(UIImageView *)bgImageView{
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"forum_bg.jpg"]];
        _bgImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, AD(250));
        _bgImageView.userInteractionEnabled = YES;
    }
    return _bgImageView;
}
-(UILabel *)tipLabel{
    if (!_tipLabel) {
        _tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(80), AD(65), SCREEN_WIDTH-AD(160), AD(20))];
        _tipLabel.textColor = [UIColor whiteColor];
        _tipLabel.font = [UIFont systemFontOfSize:AD(12)];
        _tipLabel.textAlignment = NSTextAlignmentCenter;
        _tipLabel.text = @"聚天下高手心水,创六合财富神话";
    }
    return _tipLabel;
}

-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(80), kStatusBarHeight, SCREEN_WIDTH-AD(160), AD(30))];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont systemFontOfSize:AD(18)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.text = @"高手论坛";
    }
    return _titleLabel;
}

-(LotteryView *)lotteryView{
    if (!_lotteryView) {
        _lotteryView = [[LotteryView alloc] initWithFrame:CGRectMake(AD(10), AD(100), SCREEN_WIDTH-AD(20), AD(100))];
        __weak typeof(self) weakSelf = self;
        _lotteryView.actionBlock = ^(NSInteger index) {
            [weakSelf changeHeaderBG:index];
        };
    }
    return _lotteryView;
}
-(MessageView *)messageView{
    if (!_messageView) {
        _messageView = [[MessageView alloc] initWithFrame:CGRectMake(AD(10), AD(200), SCREEN_WIDTH-AD(20), AD(80))];
    }
    return _messageView;
}

-(TabTitleView *)tabView{
if (!_tabView) {
    CGFloat y = _messageView.bottom + AD(10);
    _tabView = [[TabTitleView alloc] initWithFrame:CGRectMake(_messageView.left, y, _messageView.width, AD(40))];

}
return _tabView;
}
@end
